package com.zxy.ziems.server.board.controller;

import com.zxy.btp.common.response.JsonResponse;
import com.zxy.btp.common.response.PageResult;
import com.zxy.ziems.server.board.pojo.dto.RoleFileDTO;
import com.zxy.ziems.server.board.pojo.vo.*;
import com.zxy.ziems.server.board.service.EntiretyBoardService;
import com.zxy.ziems.server.board.service.RoleFileService;
import com.zxy.ziems.server.constant.enums.DictCodeEnum;
import com.zxy.ziems.server.device.pojo.enums.AlarmTreeFilterEnum;
import com.zxy.ziems.server.file.vo.FileVO;
import com.zxy.ziems.server.mybatis.core.pojo.PageParam;
import com.zxy.ziems.server.scene.service.SceneService;
import com.zxy.ziems.server.vo.ChartVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 整体看板
 */
@RestController
@RequestMapping("/api/dataBoard/entirety")
public class EntiretyBoardController {

    @Autowired
    private EntiretyBoardService entiretyBoardService;
    @Autowired
    private RoleFileService roleFileService;
    @Autowired
    private SceneService service;

    /**
     * 本月系统累计
     * @return
     */
    @GetMapping("/curMonth")
    public JsonResponse<CurMonthChangeDosageVo> curMonth() {
        return JsonResponse.SUCCESS(entiretyBoardService.getCurMonth());
    }

    /**
     * 能源统计
     * @return
     */
    @GetMapping("/energyStatistics")
    public JsonResponse<EnergyVo> energyStatistics() {
        return JsonResponse.SUCCESS(entiretyBoardService.energyStatistics());
    }

    /**
     * 上月耗电和水用量
     * @return
     */
    @GetMapping("/lastMonthDosage")
    public JsonResponse<Map<String, List<DosageVo>>> lastMonthDosage() {
        return JsonResponse.SUCCESS(entiretyBoardService.lastMonthElectricityAndWater());
    }

    /**
     * 上月燃气用量
     * @return
     */
    @GetMapping("/lastMonthGas")
    public JsonResponse<ChartVo> lastMonthGas() {
        return JsonResponse.SUCCESS(entiretyBoardService.lastMonthGas());
    }

    /**
     * 釜运行状态
     * @return
     */
    @GetMapping("/deviceStatus")
    public JsonResponse<List<DeviceStatusVo>> deviceStatus() {
        return JsonResponse.SUCCESS(entiretyBoardService.deviceStatus(DictCodeEnum.PRODUCT_BOARD));
    }

    /**
     * 添加角色文件
     * @param roleFileDTO
     * @return
     */
    @PostMapping("/addRoleFile")
    public JsonResponse<Void> addRoleFile(@Validated(RoleFileDTO.Add.class) @RequestBody RoleFileDTO roleFileDTO) {
        roleFileService.addRoleFile(roleFileDTO);
        return JsonResponse.SUCCESS();
    }

    /**
     * 获取文件
     * @param pageParam
     * @return
     */
    @GetMapping("/getRoleFile")
    public PageResult<RoleFileVo> getRoleFile(@Validated PageParam pageParam) {
        return roleFileService.getRoleFile(pageParam);
    }

    /**
     * 删除文件
     * @param roleFileDTO
     * @return
     */
    @PostMapping("/removeFile")
    public JsonResponse<Void> removeFile(@Validated(RoleFileDTO.Delete.class) @RequestBody RoleFileDTO roleFileDTO) {
        roleFileService.removeFile(roleFileDTO.getRoleFileId());
        return JsonResponse.SUCCESS();
    }

    /**
     * 其他图片
     * @return
     */
    @GetMapping("/scene/other")
    public JsonResponse<List<FileVO>> other() {

        return JsonResponse.SUCCESS(service.childSceneFileByCode(AlarmTreeFilterEnum.OTHER.getCode()));
    }
}
